import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'
var routemap = null;
var utype = JSON.parse(localStorage.getItem("userInfo")).u_type;

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in subMenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if false, the item will hidden in breadcrumb(default is true)
  }
**/
//经理，系统管理员
export const constantRouterMap = [
	{
		path: '/login',
		component: () => import('@/views/login/index'),
		hidden: true
	},
	{
		path: '/404',
		component: () => import('@/views/404'),
		hidden: true
	},

	{
		path: '/',
		component: Layout,
		redirect: '/dashboard',
		name: 'dashboard',
		meta: {
			title: '首页'
		},
		hidden: true,
		children: [{
			path: 'dashboard',
			component: () => import('@/views/dashboard/index')
		}]
	},

	{
		path: '/goodsmanagement',
		component: Layout,
		redirect: '/goodsmanagement/goods_list',
		name: 'goodsmanagement',
		meta: {
			title: '商品',
			icon: 'shangpin'
		},
		children: [{
				path: '/goodsmanagement/goods_list',
				name: 'goods_list',
				component: () => import('@/views/goodsmanagement/goods_list'),
				meta: {
					title: '商品列表',
					icon: 'liebiao'
				}
			},
			{
				path: '/goodsmanagement/goods_stock',
				name: 'goods_stock',
				component: () => import('@/views/goodsmanagement/goods_stock'),
				meta: {
					title: '商品库存',
					icon: 'kucun'
				}
			},
				{
				path: '/goodsmanagement/put_storage',
				name: 'put_storage',
				component: () => import('@/views/goodsmanagement/put_storage'),
				meta: {
					title: '商品入库',
					icon: 'ruku'
				}
			},
				{
				path: '/goodsmanagement/outbound',
				name: 'outbound',
				component: () => import('@/views/goodsmanagement/outbound'),
				meta: {
					title: '商品出库',
					icon: 'chukuguanli'
				}
			},
			{
				path: '/goodsmanagement/sizemanagement',
				name: 'sizemanagement',
				component: () => import('@/views/goodsmanagement/sizemanagement'),
				meta: {
					title: '尺码管理',
					icon: '尺码'
				}
			},
			{
				path: '/goodsmanagement/colormanagement',
				name: 'colormanagement',
				component: () => import('@/views/goodsmanagement/colormanagement'),
				meta: {
					title: '颜色管理',
					icon: 'yanse'
				}
			}
		]
	},

	{
		path: '/order',
		component: Layout,
		redirect: '/order/purchase_order',
		name: 'order',
		meta: {
			title: '订单',
			icon: 'nested'
		},
		children: [{
				path: '/order/purchase_order',
				component: () => import('@/views/order/purchase_order'), // Parent router-view
				name: 'purchase_order',
				meta: {
					title: '订货单',
					icon: 'dingdan'
				},
			},
			{
				path: '/order/returns_order',
				component: () => import('@/views/order/returns_order'),
				name: 'returns_order',
				meta: {
					title: '退货单',
					icon: 'tuidanguanli'
				}
			},
			{
				path: '/order/order_statistics',
				component: () => import('@/views/order/order_statistics'),
				name: 'order_statistics',
				meta: {
					title: '订单商品统计',
					icon:'统计'
				}
			},
// 			{
// 				path: '/order/outbound',
// 				component: () => import('@/views/order/outbound'),
// 				name: 'outbound',
// 				meta: {
// 					title: '出库发货记录'
// 				}
// 			}
		]
	},
	{
		path: '/customer',
		component: Layout,
		name: 'customer',
		meta: {
			title: '人员管理',
			icon: 'example'
		},
		children: [{
			path: '/customer/index',
			name: 'customerindex',
			component: () => import('@/views/customer/index'),
			meta: {
				title: '人员管理',
				icon: '客户'
			}
		}]
	},
	{
		path: '/report',
		component: Layout,
		redirect: '/report/order_report',
		name: 'report',
		meta: {
			title: '报表',
			icon: 'baobiao1'
		},
		children: [{
				path: '/report/order_report',
				component: () => import('@/views/report/order_report'), // Parent router-view
				name: 'order_report',
				meta: {
					title: '订单统计报表',
					icon: 'baobiao2'
				},
			},
			{
				path: '/report/goods_sale_report',
				component: () => import('@/views/report/goods_sale_report'),
				name: 'goods_sale_report',
				meta: {
					title: '商品销售报表',
					icon: 'baobiao'
				}
			},
			{
				path: '/report/customer_report',
				component: () => import('@/views/report/customer_report'),
				name: 'customer_report',
				meta: {
					title: '客户订货报表',
					icon: 'baobiao'
				}
			}
		]
	},

	{
		path: '*',
		redirect: '/404',
		hidden: true
	}
]

//客户
export const constantRouterMap1 = [
	{
		path: '/login',
		component: () => import('@/views/login/index'),
		hidden: true
	},
	{
		path: '/404',
		component: () => import('@/views/404'),
		hidden: true
	},

	{
		path: '/',
		component: Layout,
		redirect: '/dashboard',
		name: 'dashboard',
		meta: {
			title: '首页'
		},
		hidden: true,
		children: [{
			path: 'dashboard',
			component: () => import('@/views/dashboard/index')
		}]
	},

	{
		path: '/user',
		component: Layout,
		redirect: '/user/goods_show',
		name: 'user',
		meta: {
			title: '商品',
			icon: 'example'
		},
		children: [{
				path: '/user/goods_show',
				name: 'goods_show',
				component: () => import('@/views/user/goods_show'),
				meta: {
					title: '商品列表',
					icon: 'table'
				}
			}
		]
	},

	{
		path: '/userorder',
		component: Layout,
		redirect: '/userorder/purchase_order',
		name: 'userorder',
		meta: {
			title: '订单',
			icon: 'nested'
		},
		children: [{
				path: '/userorder/put_order',
				component: () => import('@/views/userorder/put_order'), // Parent router-view
				name: 'put_order',
				meta: {
					title: '订货单'
				},
			},
			{
				path: '/userorder/return_order',
				component: () => import('@/views/userorder/return_order'),
				name: 'returns_order',
				meta: {
					title: '退货单'
				}
			},
		]
	},
	{
		path: '/user_message',
		component: Layout,
		name: 'user_message',
		meta: {
			title: '个人信息',
			icon: 'example'
		},
		children: [{
			path: '/user_message/index',
			name: 'usermessage',
			component: () => import('@/views/user_message/index'),
			meta: {
				title: '个人信息',
				icon: 'table'
			}
		}]
	},

	{
		path: '*',
		redirect: '/404',
		hidden: true
	}
]

//仓库管理员
export const constantRouterMap2 = [
	{
		path: '/login',
		component: () => import('@/views/login/index'),
		hidden: true
	},
	{
		path: '/404',
		component: () => import('@/views/404'),
		hidden: true
	},

	{
		path: '/',
		component: Layout,
		redirect: '/dashboard',
		name: 'dashboard',
		meta: {
			title: '首页'
		},
		hidden: true,
		children: [{
			path: 'dashboard',
			component: () => import('@/views/dashboard/index')
		}]
	},

	{
		path: '/goodsmanagement',
		component: Layout,
		redirect: '/goodsmanagement/goods_list',
		name: 'goodsmanagement',
		meta: {
			title: '商品',
			icon: 'shangpin'
		},
		children: [{
				path: '/goodsmanagement/goods_list',
				name: 'goods_list',
				component: () => import('@/views/goodsmanagement/goods_list'),
				meta: {
					title: '商品列表',
					icon: 'liebiao'
				}
			},
			{
				path: '/goodsmanagement/goods_stock',
				name: 'goods_stock',
				component: () => import('@/views/goodsmanagement/goods_stock'),
				meta: {
					title: '商品库存',
					icon: 'kucun'
				}
			},
				{
				path: '/goodsmanagement/put_storage',
				name: 'put_storage',
				component: () => import('@/views/goodsmanagement/put_storage'),
				meta: {
					title: '商品入库',
					icon: 'ruku'
				}
			},
				{
				path: '/goodsmanagement/outbound',
				name: 'outbound',
				component: () => import('@/views/goodsmanagement/outbound'),
				meta: {
					title: '商品出库',
					icon: 'chukuguanli'
				}
			},
			{
				path: '/goodsmanagement/sizemanagement',
				name: 'sizemanagement',
				component: () => import('@/views/goodsmanagement/sizemanagement'),
				meta: {
					title: '尺码管理',
					icon: '尺码'
				}
			},
			{
				path: '/goodsmanagement/colormanagement',
				name: 'colormanagement',
				component: () => import('@/views/goodsmanagement/colormanagement'),
				meta: {
					title: '颜色管理',
					icon: 'yanse'
				}
			}
		]
	},

	{
		path: '/order',
		component: Layout,
		redirect: '/order/purchase_order',
		name: 'order',
		meta: {
			title: '订单',
			icon: 'nested'
		},
		children: [{
				path: '/order/purchase_order',
				component: () => import('@/views/order/purchase_order'), // Parent router-view
				name: 'purchase_order',
				meta: {
					title: '订货单',
					icon: 'dingdan'
				},
			},
			{
				path: '/order/returns_order',
				component: () => import('@/views/order/returns_order'),
				name: 'returns_order',
				meta: {
					title: '退货单',
					icon: 'tuidanguanli'
				}
			},
			{
				path: '/order/order_statistics',
				component: () => import('@/views/order/order_statistics'),
				name: 'order_statistics',
				meta: {
					title: '订单商品统计',
					icon:'统计'
				}
			},
		]
	},
	{
		path: '/user_message',
		component: Layout,
		name: 'user_message',
		meta: {
			title: '个人信息',
			icon: 'example'
		},
		children: [{
			path: '/user_message/index',
			name: 'usermessage',
			component: () => import('@/views/user_message/index'),
			meta: {
				title: '个人信息',
				icon: 'table'
			}
		}]
	},
	{
		path: '*',
		redirect: '/404',
		hidden: true
	}
]


//业务员
export const constantRouterMap3 = [
	{
		path: '/login',
		component: () => import('@/views/login/index'),
		hidden: true
	},
	{
		path: '/404',
		component: () => import('@/views/404'),
		hidden: true
	},

	{
		path: '/',
		component: Layout,
		redirect: '/dashboard',
		name: 'dashboard',
		meta: {
			title: '首页'
		},
		hidden: true,
		children: [{
			path: 'dashboard',
			component: () => import('@/views/dashboard/index')
		}]
	},
	{
		path: '/order',
		component: Layout,
		redirect: '/order/purchase_order',
		name: 'order',
		meta: {
			title: '订单',
			icon: 'nested'
		},
		children: [{
				path: '/order/purchase_order',
				component: () => import('@/views/order/purchase_order'), // Parent router-view
				name: 'purchase_order',
				meta: {
					title: '订货单',
					icon: 'dingdan'
				},
			},
			{
				path: '/order/returns_order',
				component: () => import('@/views/order/returns_order'),
				name: 'returns_order',
				meta: {
					title: '退货单',
					icon: 'tuidanguanli'
				}
			}
		]
	},
	{
		path: '/user_message',
		component: Layout,
		name: 'user_message',
		meta: {
			title: '个人信息',
			icon: 'example'
		},
		children: [{
			path: '/user_message/index',
			name: 'usermessage',
			component: () => import('@/views/user_message/index'),
			meta: {
				title: '个人信息',
				icon: 'table'
			}
		}]
	},
	{
		path: '*',
		redirect: '/404',
		hidden: true
	}
]


//财务
export const constantRouterMap4 = [
	{
		path: '/login',
		component: () => import('@/views/login/index'),
		hidden: true
	},
	{
		path: '/404',
		component: () => import('@/views/404'),
		hidden: true
	},

	{
		path: '/',
		component: Layout,
		redirect: '/dashboard',
		name: 'dashboard',
		meta: {
			title: '首页'
		},
		hidden: true,
		children: [{
			path: 'dashboard',
			component: () => import('@/views/dashboard/index')
		}]
	},
	{
		path: '/order',
		component: Layout,
		redirect: '/order/purchase_order',
		name: 'order',
		meta: {
			title: '订单',
			icon: 'nested'
		},
		children: [{
				path: '/order/purchase_order',
				component: () => import('@/views/order/purchase_order'), // Parent router-view
				name: 'purchase_order',
				meta: {
					title: '订货单',
					icon: 'dingdan'
				},
			},
			{
				path: '/order/returns_order',
				component: () => import('@/views/order/returns_order'),
				name: 'returns_order',
				meta: {
					title: '退货单',
					icon: 'tuidanguanli'
				}
			}
		]
	},
	{
		path: '/user_message',
		component: Layout,
		name: 'user_message',
		meta: {
			title: '个人信息',
			icon: 'example'
		},
		children: [{
			path: '/user_message/index',
			name: 'usermessage',
			component: () => import('@/views/user_message/index'),
			meta: {
				title: '个人信息',
				icon: 'table'
			}
		}]
	},
	{
		path: '*',
		redirect: '/404',
		hidden: true
	}
]

export default new Router({
	// mode: 'history', //后端支持可开
	scrollBehavior: () => ({
		y: 0
	}),
	
// 	if( utype == '1'){
// 		routemap = constantRouterMap;
// 	}else if( utype == '2'){
// 		routemap = constantRouterMap1;
// 	}else if( utype == '3'){
// 		routemap = constantRouterMap2;
// 	}else if( utype == '4'){
// 		routemap = constantRouterMap3;
// 	}else {
// 		routemap = constantRouterMap4;
// 	}
	routes: utype == '1' ? constantRouterMap: (utype == '2' ? constantRouterMap1 : (utype == '3' ? constantRouterMap2 : (utype == '4' ? constantRouterMap3 : constantRouterMap4 )))
	//(this.utype == '4' ? constantRouterMap3 : (this.utype == '5' ? constantRouterMap4 ) ) ))
	// routes:constantRouterMap
})
